/**
 * 详情对话框
 */
var PresentInfoDlg = {
    data: {
        goodsId: "",
        playerId: "",
        userName: "",
        text: "",
        watch: "",
        praise: "",
        mark: "",
        status: "",
        content: "",
        adminName: "",
        deptid: "",
        recordStatus: ""
    }
};

layui.use(['form', 'admin', 'ax'], function (){
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
 /*   admin.iframeAuto();*/

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/present/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('presentForm', result.data);
    //初始化图片
    var graphicList = result.data.graphicList;
    for(var i=0;i<graphicList.length;i++){
        var img = graphicList[i].img;
        $("#pic_big").append('<img  src="'+Feng.ctxPath+img+'" width="100px" height="100px" layer-src="'+Feng.ctxPath+img+'" alt="'+i+'" >');
    }
    form.render();
    layer.photos({
        photos: '#pic_big'
        ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/present/editItem", function (data) {
            Feng.success("更新成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });

    /**
     * 点击查看详情
     * @param data
     */

    PresentInfoDlg.openDetailDlg = function (goodsId) {
        admin.putTempData('formOk', false);

        admin.open({
            type: 2,
            title: '商品信息',
            anim: 1,
            area:["70%","70%"],
            maxmin:'true',
            content: Feng.ctxPath + '/goods/goodsDetail?id=' +goodsId,
            end: function () {
                admin.getTempData('formOk');
            }
        });
    };

    $("#relationGoods").click(function () {
        if($("#goodsName").val()=="商品不存在"){
            return false;
        }
        PresentInfoDlg.openDetailDlg($("#goodsId").val())
    })



});